home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / CHIPCD_02_2002.iso / Internet / Macromedia ColdFusion Server 5 / coldfusion-50-win-us.exe / data1.cab / Examples / CFDOCS / snippets / cfquery.cfm < prev    next >
Encoding:
Text File  |  2001-06-13  |  2.1 KB  |  77 lines

  1. <!--- This example shows the use of CreateTimeSpan with CFQUERY --->
  2. <HTML>
  3. <HEAD>
  4.     <TITLE>CFQUERY Example</TITLE>
  5. </HEAD>
  6.  
  7. <BODY  bgcolor="#FFFFD4">
  8.  
  9. <H3>CFQUERY Example</H3>
  10.  
  11. <!--- define startrow and maxrows to facilitate
  12. 'next N' style browsing --->
  13. <CFPARAM name="MaxRows" default="10">
  14. <CFPARAM name="StartRow" default="1">
  15.  
  16. <!----------------------------------------------------------------- 
  17. Query database for information if cached database information has 
  18. not been updated in the last six hours; otherwise, use cached data.
  19. ------------------------------------------------------------------->
  20. <CFOUTPUT>
  21. <CFQUERY NAME="GetParks" DATASOURCE="cfsnippets" CACHEDWITHIN="#CreateTimeSpan(0, 6, 0, 0)#">
  22. SELECT      PARKNAME, REGION, STATE
  23. FROM         Parks 
  24. ORDER by ParkName, State
  25. </CFQUERY>
  26. </CFOUTPUT>
  27.  
  28. <!--- build HTML table to display query --->
  29. <TABLE cellpadding=1 cellspacing=1>
  30. <TR>
  31.     <TD colspan=2 bgcolor=f0f0f0>
  32.     <B><I>Park Name</I></B>
  33.     </TD>
  34.     <TD bgcolor=f0f0f0>
  35.     <B><I>Region</I></B>
  36.     </TD>
  37.     <TD bgcolor=f0f0f0>
  38.     <B><I>State</I></B>
  39.     </TD>
  40. </TR>
  41.  
  42. <!--- Output the query and define the startrow and maxrows
  43.       parameters. Use the query variable CurrentCount to
  44.       keep track of the row you are displaying. --->
  45. <CFOUTPUT query="GetParks" StartRow="#StartRow#" MAXROWS="#MaxRows#">
  46. <TR>
  47.     <TD valign=top bgcolor=ffffed>
  48.     <B>#GetParks.CurrentRow#</B>
  49.     </TD>
  50.     <TD valign=top>
  51.     <FONT SIZE="-1">#ParkName#</FONT>
  52.     </TD>
  53.     <TD valign=top>
  54.     <FONT SIZE="-1">#Region#</FONT>
  55.     </TD>
  56.     <TD valign=top>
  57.     <FONT SIZE="-1">#State#</FONT>
  58.     </TD>
  59. </TR>
  60. </CFOUTPUT>
  61.  
  62. <!--- If the total number of records is less than or equal
  63. to the total number of rows, then offer a link to
  64. the same page, with the startrow value incremented by
  65. maxrows (in the case of this example, incremented by 10) --->
  66. <TR>
  67.     <TD colspan=4>
  68.     <CFIF (StartRow + MaxRows) LTE GetParks.RecordCount>
  69.         <a href="cfquery.cfm?startrow=<CFOUTPUT>#Evaluate(StartRow + MaxRows)#</CFOUTPUT>">See next <CFOUTPUT>#MaxRows#</CFOUTPUT> rows</A>
  70.     </CFIF>
  71.     
  72.     </TD>
  73. </TR>
  74. </TABLE>
  75. </BODY>
  76. </HTML>
  77.